import { defineStore } from 'pinia'
import { ref, computed } from 'vue'

export const useCounterStore = defineStore(
  'counter',
  () => {
    // 定义 state
    const count = ref(0)

    // 定义 getters
    const double = computed(() => count.value * 2)

    // 定义 actions
    const increment = () => {
      count.value++
    }

    const decrement = () => {
      count.value--
    }

    // 千万不要忘记这里要 return
    return { count, double, increment, decrement }
  },
  {
    // @ts-ignore
    unistorage: {
      key: 'abc',
      paths: ['count'],
    }, // 开启后对 state 的数据读写都将持久化
  }
)
